package hu.rsc.forbiddenwords.server;

import hu.rsc.forbiddenwords.server.persistent.Application;
import hu.rsc.forbiddenwords.server.persistent.Entry;
import hu.rsc.forbiddenwords.server.persistent.Language;
import hu.rsc.forbiddenwords.shared.ApplicationDTO;
import hu.rsc.forbiddenwords.shared.EntryDTO;
import hu.rsc.forbiddenwords.shared.LanguageDTO;

public class DtoFactory {
    public static ApplicationDTO getApplicationDTO(Application e, String userinfo) {
	ApplicationDTO d = new ApplicationDTO(e.getKey().getId());
	d.setUserInfo(e.getUserinfo());
	d.setName(e.getName());
	d.setLanguage(e.getLanguage());
	d.setOpened(e.isOpened());
	d.setEditable(e.getUserinfo().equals(userinfo));
	return d;
    }

    public static EntryDTO getEntryDTO(Entry e) {
	EntryDTO d = new EntryDTO(e.getKey().getId());

	d.setApplication(e.getApplication() != null ? e.getApplication().getId() : 0l);
	d.setCount(e.getCount());
	d.setWord(e.getWord());
	return d;
    }

    public static LanguageDTO getLanguageDTO(Language e) {
	LanguageDTO d = new LanguageDTO(e.getKey().getId());
	d.setName(e.getName());
	d.setCode(e.getCode());
	return d;
    }
}
